<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="js/web3.js"></script>
</head>
<body>

    <input type="button" value="注册账号">
    <input type="button" value="查询账号">
    <input type="button" value="解锁账号">
    <br><br>

    账号: <input type="text" id="account">
    <input type="button" value="查询余额" id="queryAccount">
    <br><br>

    转账账号: <input type="text" id="sender">
    接收账号: <input type="text" id="receiver">
    <input type="button" value="确定" id="transfer">

    <script>

        var web3=new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));


        //注册账户
        document.querySelectorAll("input")[0].onclick=function(){
            web3.personal.newAccount("123456", function(error, result){
                console.log(result);
            });

        }

        //查询账户列表
        document.querySelectorAll("input")[1].onclick=function(){
            web3.eth.getAccounts(function(error, result){
                console.log(result);
            })
        }

        //解锁账户
        document.querySelectorAll("input")[2].onclick=function(){
            web3.personal.unlockAccount("0x86eabd04e18cf2db6918997633e5769e61022a47", "123456", function(error, result){
                console.log(result);
            })
        }

        //查询账户余额
        document.getElementById("queryAccount").onclick=function(){
            var account=document.getElementById("account").value;
            web3.eth.getBalance(account, function(error, result){
                console.log(result);
            })
        }

        //转账
        document.getElementById("transfer").onclick=function(){
            var sender=document.getElementById("sender").value;
            var receiver=document.getElementById("receiver").value;

            web3.eth.sendTransaction({
                from: sender,
                to: receiver,
                value: '1000000000000000'

            }, function(error, result){
                console.log(result);
            })
        }

    </script>


</body>
</html>